
export class ICursor {
    constructor() {
        this.m_x = 0;
        this.m_y = 0;
        this.m_width = 1;
        this.m_height = 16;
        this.m_viewport_x = 0;
        this.m_viewport_y = 0;
        this.m_viewport_width = 0;
        this.m_viewport_height = 0;
        this.m_visible = false;
        this.m_flicker = false;
        this.m_flicker_interval = 500;
        this.m_flicker_timestamp = 0;
        this.m_foreground_color = "black";
        this.m_background_color = "white";
    }

    SetVisible(visible) { this.m_visible = visible; }
    IsVisible() { return this.m_visible; }
    SetFlicker(flicker) { this.m_flicker = flicker; }
    IsFlicker() { return this.m_flicker; }
    SetFlickerInterval(interval) { this.m_flicker_interval = interval; }

    GetX() { return this.m_x; }
    GetY() { return this.m_y; }
    GetWidth() { return this.m_width; }
    GetHeight() { return this.m_height; }
    GetBackgroundColor() { return this.m_background_color; }
    GetForegroundColor() { return this.m_foreground_color; }
    GetViewPortX() { return this.m_viewport_x; }
    GetViewPortY() { return this.m_viewport_y; }
    GetViewPortWidth() { return this.m_viewport_width; }
    GetViewPortHeight() { return this.m_viewport_height; }

    SetX(x) { this.m_x = x; }
    SetY(y) { this.m_y = y; }
    SetWidth(width) { this.m_width = width; }
    SetHeight(height) { this.m_height = height; }
    SetBackgroundColor(color) { this.m_background_color = color; }
    SetForegroundColor(color) { this.m_foreground_color = color; }
    SetViewPortX(x) { this.m_viewport_x = x; }
    SetViewPortY(y) { this.m_viewport_y = y; }
    SetViewPortWidth(width) { this.m_viewport_width = width; }
    SetViewPortHeight(height) { this.m_viewport_height = height; }

    GetCurrentTimeStamp() { return Date.now(); }
    GetFlickerTimeStamp() { return this.m_flicker_timestamp; }
    SetFlickerTimeStamp(timestamp) { this.m_flicker_timestamp = timestamp; }
    GetFlickerInterval() { return this.m_flicker_interval; }

    Render(painter) {
        if (!this.IsFlicker() || (this.GetCurrentTimeStamp() - this.GetFlickerTimeStamp() < this.GetFlickerInterval())) return;
        this.SetVisible(!this.IsVisible());
        this.SetFlickerTimeStamp(this.GetCurrentTimeStamp());

        painter.Save();
        painter.Clip(this.GetViewPortX(), this.GetViewPortY(), this.GetViewPortWidth(), this.GetViewPortHeight());
        if (this.IsVisible()) {
            painter.FillRectangle(this.GetX(), this.GetY(), this.GetWidth(), this.GetHeight(), this.GetForegroundColor());
        } else {
            painter.FillRectangle(this.GetX(), this.GetY(), this.GetWidth(), this.GetHeight(), this.GetBackgroundColor());
        }
        painter.Restore();
    }
}